﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DTO;
using BUS;

namespace GUI
{
    public partial class FormDanhSachLoaiXe : Form
    {
        public FormDanhSachLoaiXe()
        {
            InitializeComponent();
        }

        private void btnthem_Click(object sender, EventArgs e)
        {
            String hangsc = txthangsx.Text;
            String maloai = txtmaloai.Text;
            int tt = Convert.ToInt32(txttrongtai.Text);
            try
            {
                BUS.LoaiXeBUS.ThemLoaiXe(hangsc, maloai, tt);
                MessageBox.Show("Insert Successfull!!");
                FormDanhSachLoaiXe_Load(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void FormDanhSachLoaiXe_Load(object sender, EventArgs e)
        {
            this.dataGridView1.DataSource = LoaiXeBUS.SelectALLLoaiXe();
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            int i = e.RowIndex;
            txthangsx.Text = dataGridView1.Rows[i].Cells[0].Value.ToString();
            txtmaloai.Text = dataGridView1.Rows[i].Cells[1].Value.ToString();
            txttrongtai.Text = dataGridView1.Rows[i].Cells[2].Value.ToString();

           
        }

        private void btnsua_Click(object sender, EventArgs e)
        {
            String hangsc = txthangsx.Text;
            String maloai = txtmaloai.Text;
            int tt = Convert.ToInt32(txttrongtai.Text);
            try
            {
                BUS.LoaiXeBUS.SuaLoaiXe(hangsc, maloai, tt);
                MessageBox.Show("Updata Successfull!!");
                FormDanhSachLoaiXe_Load(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnxoa_Click(object sender, EventArgs e)
        {
            
            String maloai = txtmaloai.Text;
           
            try
            {
                BUS.LoaiXeBUS.XoaLoaiXe( maloai);
                MessageBox.Show("Delete Successfull!!");
                FormDanhSachLoaiXe_Load(null, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnthoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
